package com.xingda.packing.dmds.rule.choose;

import com.xingda.packing.dmds.domain.ProductBox;
import com.xingda.packing.dmds.domain.Wheel;
import com.xingda.packing.dmds.enums.BoxTaskType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Order(5)
@Component("wheelPkInvbasdocDMDSChoose")
@Slf4j
public class WheelPkInvbasdocChoose implements ChooseService {

    @Override
    public boolean canChoose(ProductBox productBox, Wheel wheel) {
        boolean result = can(productBox, wheel);
        if (!result) {
            log.info("box:{}, 工字轮条码：{}，物料编号判断->{}",productBox.getBoxNo(), wheel.getBarCode(), false);
        }
        return result;
    }

    private boolean can(ProductBox productBox, Wheel wheel) {
        if (productBox.getType() == BoxTaskType.PACKING_CLEAN.getTypeId()) {
            return true;
        }
        if (productBox.getType() == BoxTaskType.PACKING_SEMI_FINISHED_DISQUALITY.getTypeId()) {
            return true;
        }
        return productBox.getType() == BoxTaskType.PACKING_FINISHED.getTypeId() && productBox.getPkInvbasdocList().contains(wheel.getPkInvbasdoc());
    }
}
